package jjn.daily;

import commons.ListNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jjn
 * @since 2023/7/31 15:12
 */
public class LeetCode143 {
    public void reorderList(ListNode head) {
        ListNode current = head;
        List<ListNode> nodes = new ArrayList<>();
        while (current != null) {
            nodes.add(current);
            current = current.next;
        }
        int left = 0, right = nodes.size() - 1;
        while (left < right) {
            nodes.get(left).next = nodes.get(right);
            left++;
            if (left == right) {
                break;
            }
            nodes.get(right).next = nodes.get(left);
            right--;
        }
        nodes.get(left).next = null;
    }
}
